package com.iRomantic.controller.manager;

import java.io.File;
import java.util.UUID;

import com.iRomantic.common.BaseController;
import com.iRomantic.common.oss.OSSService;
import com.iRomantic.common.util.FileUtil;
import com.iRomantic.config.Constant;
import com.iRomantic.domain.entity.Enterprise;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.upload.UploadFile;

public class EnterpriseController extends BaseController {
	
	/**
	 * 创建婚期企业
	 * @throws Exception 
	 */
	public void create() throws Exception{
		
		String path = this.getSession().getServletContext().getRealPath(Constant.TEMP_FOLDER);
		//图片处理
		UploadFile picture = this.getFile("enterprise.picture",path);
		Enterprise enterprise = this.getModel(Enterprise.class);
		enterprise.set("id",UUID.randomUUID().toString());
		if(picture!=null){
			String pictureName = FileUtil.randomFileName(picture.getFileName());
			enterprise.set("picture", pictureName);
			OSSService.getInstance().save(Constant.ENTERPRISE_PICTURE+enterprise.getStr("id")+"/"+enterprise.getStr("picture"), picture.getFile());
			//picture.getFile().renameTo(new File(path,pictureName));
			picture.getFile().delete();
		}
		enterprise.save();
			
		this.renderJson(enterprise);
		
	}

}
